package cn.licoy.wdog.core.controller.hospital;

import cn.licoy.wdog.common.annotation.SysLogs;
import cn.licoy.wdog.common.bean.ResponseCode;
import cn.licoy.wdog.common.bean.ResponseResult;
import cn.licoy.wdog.core.entity.hospital.Department;
import cn.licoy.wdog.core.service.hospital.DepartmentService;
import com.baomidou.mybatisplus.plugins.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * 医院端部门操作
 * @author Sunne
 * Create time 2018/6/22 14:03
 * @return null
 **/
@RestController
@RequestMapping(value = "/department")
@Api(tags = {"第一期--医院部门操作"})
public class DepartmentController {
    @Autowired
    DepartmentService departmentService;
    @PostMapping(value = {"/add"})
    @ApiOperation(value = "新增部门")
    @SysLogs("新增部门")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token")
    public ResponseResult add(
            @RequestBody @Validated  @ApiParam(value = "部门名称") @RequestParam(value = "departmentname", required = false) String departmentname){
        if("".equals(departmentname)||departmentname==null){
            return ResponseResult.e(ResponseCode.FAIL,"departmentname不能为空");
        }
        Department department = new Department();
        department.setName(departmentname);
        department.setCreateDate(new Date());
        department.setRemake("1");
        departmentService.insert(department);
        return ResponseResult.e(ResponseCode.OK,"新增部门完成");
    }

    @PostMapping(value = {"/selectall"})
    @ApiOperation(value = "查询所有部门")
    @SysLogs("查询所有部门")
    @ApiImplicitParam(paramType = "header",name = "Authorization",value = "身份认证Token")
    public ResponseResult selectAll(){
        Page<Department> pd = departmentService.selectPage(new Page<>(0,20));
        return ResponseResult.e(ResponseCode.OK,pd);
    }
}